package com.hengmei.smallscreen.app

import android.content.Context
import androidx.multidex.MultiDexApplication
import com.hengmei.smallscreen.db.datebase.AppDatabase
import com.hengmei.smallscreen.mmkv.MMKVOwner
import com.hjq.language.MultiLanguages
import com.kongzue.dialogx.DialogX
import com.orhanobut.logger.AndroidLogAdapter
import com.orhanobut.logger.Logger
import com.orhanobut.logger.PrettyFormatStrategy
import com.tencent.mmkv.MMKV


class MyApp : MultiDexApplication() {

    companion object {
        lateinit var instance: MyApp

        fun get(): MyApp {
            return instance
        }
    }

    override fun onCreate() {
        super.onCreate()
        instance = this
//        MultiDex.install(this)
        val dir = filesDir.absolutePath + "/mmkv_hengmei"
        MMKV.initialize(this, dir)
        MMKVOwner.default = MMKV.defaultMMKV()

        DialogX.init(this);

        // 初始化
//
        AppDatabase.getDatabase(this)
        var formatStrategy = PrettyFormatStrategy.newBuilder()
        formatStrategy.tag("hengmei").build()
        Logger.addLogAdapter(AndroidLogAdapter())

        // 初始化语种切换框架
        MultiLanguages.init(this)
        //初始化 HBluetooth
//        HBluetooth.init(this);
//        HBluetooth.getInstance().connectTimeOut = 10000;
    }

    override fun attachBaseContext(base: Context?) {
        // 绑定语种
        super.attachBaseContext(MultiLanguages.attach(base))
    }
}